package org.jbfilter.test.beans.factory;

import java.util.ArrayList;
import java.util.Collection;

import org.jbfilter.test.beans.Composer;
import org.jbfilter.test.beans.Country;
import org.jbfilter.test.beans.Utils;

public class ComposerFactory {

	private static ComposerFactory instance; 
	
	private Composer andersson;
	private Composer bach;
	private Composer beethoven;
	private Composer bizet;
	private Composer brahms;
	private Composer mahler;
	private Composer menotti;
	private Composer mozart;
	private Composer puccini;
	private Composer ravel;
	private Composer schubert;
	private Composer richardStrauss;
	private Composer wagner;
	private Collection<Composer> composers = new ArrayList<Composer>();
	
	public static ComposerFactory getInstance() {
		if (instance == null) {
			instance = new ComposerFactory();
		}
		return instance;
	}

	private ComposerFactory() {
		super();
		long id = 0;
		andersson = createComposer(++id, "Benny", null, "Andersson", "16/12/1946", null, Country.SWEDEN);
		bach = createComposer(++id, "Johann Sebastian", null, "Bach", "21/03/1685", "28/07/1750", Country.GERMANY);
		beethoven = createComposer(++id, "Ludwig", "van", "Beethoven", "16/12/1770", "26/03/1826", Country.GERMANY);
		bizet = createComposer(++id, "Georges", null, "Bizet", "25/10/1838", "03/06/1875", Country.FRANCE);
		brahms = createComposer(++id, "Johannes", null, "Brahms", "07/05/1833", "03/04/1897", Country.GERMANY);
		// set time for brahm's died date
		brahms.setDied(Utils.createDateTime("03/04/1897 08:32:26"));
		mahler = createComposer(++id, "Gustav", null, "Mahler", "07/07/1860", "18/05/1911", Country.AUSTRIA);
		menotti = createComposer(++id, "Gian Carlo", null, "Menotti", "07/07/1911", "01/02/2007", Country.USA);
		mozart = createComposer(++id, "Wolfgang Amadeus", null, "Mozart", "27/01/1756", "05/12/1791", Country.GERMANY);
		puccini = createComposer(++id, "Giacomo", null, "Puccini", "22/12/1858", "29/11/1924", Country.ITALY);
		ravel = createComposer(++id, "Maurice", null, "Ravel", "07/03/1875", "28/12/1937", Country.FRANCE);
		schubert = createComposer(++id, "Franz", null, "Schubert", "31/01/1797", "19/11/1828", Country.AUSTRIA);
		richardStrauss = createComposer(++id, "Richard", null, "Strauss", "11/06/1864", "08/09/1949", Country.GERMANY);
		wagner = createComposer(++id, "Richard", null, "Wagner", "22/05/1813", "13/02/1883", Country.GERMANY);
	}

	private Composer createComposer(
			Long id,
			String first,
			String particle,
			String last,
			String born_dd_MM_yyyy,
			String died_dd_MM_yyyy,
			Country country) {
		Composer comp = new Composer();
		comp.setId(id);
		comp.setFirstName(first);
		comp.setParticle(particle);
		comp.setLastName(last);
		comp.setBorn(Utils.createDate(born_dd_MM_yyyy));
		comp.setDied(Utils.createDate(died_dd_MM_yyyy));
		comp.setCountry(country);
		// add to list
		composers.add(comp);
		return comp;
	}
	public Collection<Composer> getAll() {
		return composers;
	}
	public Composer getAndersson() {
		return andersson.clone();
	}
	public Composer getBach() {
		return bach.clone();
	}
	public Composer getBeethoven() {
		return beethoven.clone();
	}
	public Composer getBizet() {
		return bizet.clone();
	}
	public Composer getBrahms() {
		return brahms.clone();
	}
	public Composer getMahler() {
		return mahler.clone();
	}
	public Composer getMenotti() {
		return menotti.clone();
	}
	public Composer getMozart() {
		return mozart.clone();
	}
	public Composer getRavel() {
		return ravel.clone();
	}
	public Composer getRichardStrauss() {
		return richardStrauss.clone();
	}
	public Composer getSchubert() {
		return schubert.clone();
	}
	public Composer getWagner() {
		return wagner.clone();
	}
	public Composer getPuccini() {
		return puccini.clone();
	}
}